package com.unionpay.mpds.web.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.StrutsStatics;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.ValueStack;
import com.unionpay.mpds.util.Constants;
import com.unionpay.mpds.util.WebUtil;
/**
 * 登陆拦截器
 * @author Administrator
 *
 */
public class LoginInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		HttpServletRequest request = (HttpServletRequest) arg0.getInvocationContext().get(StrutsStatics.HTTP_REQUEST);
		Map<String,Object> session = arg0.getInvocationContext().getSession();
		ValueStack valueStack=arg0.getInvocationContext().getValueStack();
		if(session.containsKey(Constants.USR_ID)){
			return arg0.invoke();
		}else{
			arg0.getInvocationContext().put("error", 3);
			if(request.getQueryString()!=null)
				session.put("backUrl", request.getRequestURL().toString()+"?"+request.getQueryString());
			else
				session.put("backUrl", request.getRequestURL().toString());
			return WebUtil.returnCode(arg0, Constants.LOGIN);
		}
	}

}
